package simulator;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.commons.math3.distribution.NormalDistribution;

public class GraphsUtils {
	
	private double alpha;
	private double iniAlpha;
	private double step;
	
	private double T1mean;
	private double T1std;
	private double T2mean;
	private double T2std;
	private double T3mean;
	private double T3std;
	
	private String dotFolderPath;
	private String graphFolderPath;
	private String referencesFile;
	private String referencesFolder;
	
	private boolean graphs;
	private boolean animation;
	private int iterations;
	private int limit;
	private int netSize;
	
	private double infectedPercentage;
	
	private static final String propertiesFolder = "resources/graphsConfiguration.properties";
	
	public GraphsUtils() {
		Properties properties = new Properties();
		
		try {
			properties.load(new FileInputStream(propertiesFolder));
		} catch (FileNotFoundException e) {
			System.out.println("ERROR: Configuration file not found");
			System.exit(0);
		} catch (IOException e) {
			System.out.println("ERROR: IOException");
			System.exit(0);
		}
		iniAlpha = Double.valueOf(properties.getProperty("alphaBudget"));
		alpha = Double.valueOf(properties.getProperty("alphaBudget"));
		step = Double.valueOf(properties.getProperty("step"));
		
		T1mean = Double.valueOf(properties.getProperty("T1mean"));
		T1std = Double.valueOf(properties.getProperty("T1std"));
		T2mean = Double.valueOf(properties.getProperty("T2mean"));
		T2std = Double.valueOf(properties.getProperty("T2std"));
		T3mean = Double.valueOf(properties.getProperty("T3mean"));
		T3std = Double.valueOf(properties.getProperty("T3std"));
		
		infectedPercentage = Double.valueOf(properties.getProperty("infectedPercentage"));
		
		dotFolderPath = String.valueOf(properties.getProperty("dotFolderPath"));
		graphFolderPath = String.valueOf(properties.getProperty("graphFolderPath"));
		referencesFile = String.valueOf(properties.getProperty("referencesFile"));
		referencesFolder = String.valueOf(properties.getProperty("referencesFolder"));
		
		graphs = Boolean.valueOf(properties.getProperty("graphs"));
		animation = Boolean.valueOf(properties.getProperty("animation"));
		iterations = Integer.valueOf(properties.getProperty("iterations"));
		limit = Integer.valueOf(properties.getProperty("limit"));
		netSize = Integer.valueOf(properties.getProperty("netSize"));
	}
	
	public void restart() {
		this.alpha = this.iniAlpha;
		
	}

	public double getAlpha() {
		return alpha;
	}
	
	public void setAlpha(double alpha) {
		this.alpha = alpha;
	}
	
	public double getBeta() {
		return 1 - alpha;
	}
	
	public double getStep(){
		return this.step;
	}
	
	public void setStep(double step){
		this.step = step;
	}
	
	public void incrementAlpha(){
		this.alpha = this.alpha + this.step;
	}
	
	// Probabilidad de no contagiarse
	public double getP1() {
		double P1 = (Math.log(this.getBeta() + 0.15) + 2)*0.5;
		return P1;
	}
	
	// Probabilidad de recuperarse
	public double getP2() {
		double P2 = (Math.log(this.getAlpha() + 0.15) + 2)*0.4;
		return P2;
	}
	
	// Tiempo en el que permanece infectada contagiando (I -> S/R)
	public double getT1() {
		return new NormalDistribution(T1mean,T1std).sample();
	}
	
	// Tiempo que se tarda en recuperarla (I -> S)
	public double getT2() {
		return new NormalDistribution(T2mean,T2std).sample();
	}
	
	// Tiempo que se tarda en arreglarla (R -> S)
	public double getT3() {
		return new NormalDistribution(T3mean,T3std).sample();
	}

	public double getRand() {
		return Math.random();
	}

	public double getInfectedPercentage() {
		return infectedPercentage;
	}

	public String getDotFolderPath() {
		return dotFolderPath;
	}

	public String getGraphFolderPath() {
		return graphFolderPath;
	}

	public String getReferencesFile() {
		return referencesFile;
	}
	
	public String getReferencesFolder() {
		return referencesFolder;
	}
	
	public boolean getGraphs() {
		return graphs;
	}

	public boolean getAnimation() {
		return animation;
	}

	public int getIterations() {
		return iterations;
	}

	public int getLimit() {
		return limit;
	}

	public int getNetSize() {
		return netSize;
	}

	public void setInfectedPercentage(double infectedPercentage) {
		this.infectedPercentage = infectedPercentage;
	}

	public void setT1mean(double t1mean) {
		T1mean = t1mean;
	}

	public void setT1std(double t1std) {
		T1std = t1std;
	}

	public void setT2mean(double t2mean) {
		T2mean = t2mean;
	}

	public void setT2std(double t2std) {
		T2std = t2std;
	}

	public void setT3mean(double t3mean) {
		T3mean = t3mean;
	}

	public void setT3std(double t3std) {
		T3std = t3std;
	}
	
	
}
